<template>
	<view>
		<search placeholder="订单号" />
	</view>
</template>

<script>
	const print = uni.requireNativePlugin('Sunmi-Print-Inner');
	var isConnect = false;
	export default {
		data() {
			return {
				lianjie: "",
			}
		},
		onLoad() {
			//PDA扫描
			var _this = this
			uni.$on('scancodedate', function(data) {
				_this.searchList(data.code)
			})
		},
		onUnload() {
			// 移除监听事件      
			uni.$off('scancodedate')
		},
		methods: {
			searchList(e) {
				this.start(e)
			},
			start(e) {
				let that = this
				print.connect(res => {
					isConnect = res.connect == "hello"
					that.print(e); //打印
				})
			},
			// 打印事件
			print(e) {
				if (isConnect) {
					this.lianjie = "isConnect连接成功，可以进行打印了"
					//打印小票
					print.printQrCode({
						text: e,
						size: 6,
						errorlevel: 0,
						align: 1
					})
					//空白行分割之前打印内容（类似走空白）
					print.printDividingline({
						style: "4",
						height: "10"
					})
					print.printText({
						text: "订单号：" + e,
						align: 1,
						size: 28,
						bold: true,
					})
					print.labelOutput()
				}
			},
		}
	}
</script>

<style>
</style>